package com.ai.vita;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

/**
 * Created by yangyj on 2016/12/28.
 */
public class ApplicationController extends AbstractController {

    @RequestMapping(value = "callService")
    @ResponseBody
    public Object callService(HttpServletRequest request) throws Exception {
        return super.callService(request);
    }

    @RequestMapping(value = "refreshView")
    public String refreshView(HttpServletRequest request, Model m) throws Exception {
        return super.refreshView(request, m);
    }

    @RequestMapping(value = "refreshPart")
    @ResponseBody
    public void refreshPart(HttpServletRequest request, HttpServletResponse response) throws Exception {
        super.refreshPart(request, response);
    }

    @RequestMapping(value = "vector")
    public String vector(HttpServletRequest request, Model m) throws Exception {
        return this.initAssist(request, m);
    }

    protected String initAssist(HttpServletRequest request, Model m) throws Exception {
        if(!m.containsAttribute("gSession")){
            m.addAttribute("gSession", new HashMap());
        }
        return super.initAssist(request, m);
    }

    protected String initView(String compCode, String title, Object options, Model m, HttpServletRequest request) throws Exception {
        if(!m.containsAttribute("gSession")){
            m.addAttribute("gSession", new HashMap());
        }
        return super.initView(compCode, title, options, m, request);
    }

}
